//
//  UIBarButtonItem+Extension.swift
//  0829-Weibo
//
//  Created by 毕仲阳 on 16/8/29.
//  Copyright © 2016年 mycompany. All rights reserved.
//

import UIKit
extension UIBarButtonItem
{
    convenience init(imageName:String?=nil,title:String?=nil,target: Any?, action: Selector?) {
        self.init()
        let button = UIButton()
        if let sel = action
        {
            button.addTarget(target, action: sel, for: UIControlEvents.touchUpInside)
        }
        if let img = imageName
        {
            button.setImage(UIImage(named:img), for: UIControlState.normal)
            button.setImage(UIImage(named: "\(img)_highlighted"), for: UIControlState.highlighted)
        }
        if let t = title {
            button.setTitle(t, for: UIControlState.normal)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
            button.setTitleColor(UIColor.gray, for: UIControlState.normal)
            button.setTitleColor(UIColor.orange, for: UIControlState.highlighted)
        }
        button.sizeToFit()
        self.customView = button
    }
}
